﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using nwrole.plugin;

namespace nwrole.testplugin {
    [Export(typeof(IPlugin))]
    public class TestPluginA : IPlugin {
        
        [NwroleConfig("Value1")]
        public string TestValue1 { get; set; }

        [NwroleConfig("Value2")]
        public int TestValue2 { get; set; }

        protected IPluginDebug debug;

        private AutoResetEvent waitEvent = new AutoResetEvent(false);

        private bool running;

        public TestPluginA() {
            TestValue1 = "Hejsan";
            TestValue2 = 5;
        }

        public void Start(IPluginDebug debug) {
            this.debug = debug;

            running = true;

            Trace.TraceInformation("TestPluginA.Start()");

            debug.Log(LogLevel.Info, "Hello from TestPluginA!", null);

            while (running)
            {
                debug.Pulse("idle");

                waitEvent.WaitOne(5000);
            }
        }

        public void Stop() {
            Trace.TraceInformation("TestPluginA.Stop()");

            running = false;
            waitEvent.Set();
        }
        
        public void ConfigurationChanged() {
            Trace.TraceInformation("TestPluginA.ConfigurationChanged()");
        }
    }
}
